﻿using System;
using System.Management;

namespace MissingLinq.Linq2Management.Model.CIMv2
{
	/// <summary>/// </summary>
	[WMIClass(Name = "Win32_Trustee", Namespace = @"root\CIMv2")]
	public class Win32Trustee
	{
		/// <summary>The domain portion of the account</summary>
		public string Domain { get; set; }

		/// <summary>The name portion of the account</summary>
		public string Name { get; set; }

		/// <summary>The SID of the trustee</summary>
		[Qualifier(Name="CIMTYPE", Data="uint8")]
		public byte[] SID { get; set; }

		/// <summary>The length of the SID in BYTES</summary>
		[Qualifier(Name="CIMTYPE", Data="uint32")]
		public UInt32 SidLength { get; set; }

		/// <summary>The SID of the trustee in string format (e.g., S-1-1-0)</summary>
		public string SIDString { get; set; }

		/// <summary>TIMECREATED</summary>
		[Qualifier(Name="CIMTYPE", Data="uint64")]
		public UInt64 TIMECREATED { get; set; }

		/// <summary>Initializes a <see cref="Win32Trustee"/></summary>
		public Win32Trustee(ManagementObject managementObject=null, ConnectionInfo connectionInfo=null) { }
		/// <summary>Converts a Win32Trustee object to a ManagementBaseObject object</summary>
		public static implicit operator ManagementBaseObject(Win32Trustee obj)
		{
			var mgmtObj = new ManagementClass(Scope_, Class_, null);
			mgmtObj["Domain"] = obj.Domain;
			mgmtObj["Name"] = obj.Name;
			mgmtObj["SID"] = obj.SID;
			mgmtObj["SidLength"] = obj.SidLength;
			mgmtObj["SIDString"] = obj.SIDString;
			mgmtObj["TIME_CREATED"] = obj.TIMECREATED;
			return mgmtObj;
		}
		/// <summary>Converts a ManagementBaseObject to a Win32Trustee object</summary>
		public static implicit operator Win32Trustee(ManagementBaseObject mgmtObj)
		{
			var obj = new Win32Trustee();
			obj.Domain = (string)mgmtObj["Domain"];
			obj.Name = (string)mgmtObj["Name"];
			obj.SID = (byte[])mgmtObj["SID"];
			obj.SidLength = (UInt32)mgmtObj["SidLength"];
			obj.SIDString = (string)mgmtObj["SIDString"];
			obj.TIMECREATED = (UInt64)mgmtObj["TIME_CREATED"];
			return obj;
		}
		private const String Scope_ = @"root\CIMv2";
		private const String Class_ = @"Win32_Trustee";
	}
	/// <summary>/// </summary>
	[WMIClass(Name = "Win32_ACE", Namespace = @"root\CIMv2")]
	public class Win32ACE
	{
		/// <summary>Bit flags representing rights granted/denied to the trustee</summary>
		[Qualifier(Name="CIMTYPE", Data="uint32")]
		public UInt32 AccessMask { get; set; }

		/// <summary>Bit flags specifying inheritance of the ACE</summary>
		[Qualifier(Name="CIMTYPE", Data="uint32")]
		public UInt32 AceFlags { get; set; }

		// values Access Allowed, Access Denied, Audit
		/// <summary>The type of ACE entry this is</summary>
		[Qualifier(Name="CIMTYPE", Data="uint32")]
		public Win32ACEAceType AceType { get; set; }

		/// <summary>The guid associated with the parent of the object these rights apply to</summary>
		public string GuidInheritedObjectType { get; set; }

		/// <summary>The guid associated with the type of object these rights apply to</summary>
		public string GuidObjectType { get; set; }

		/// <summary>TIMECREATED</summary>
		[Qualifier(Name="CIMTYPE", Data="uint64")]
		public UInt64 TIMECREATED { get; set; }

		/// <summary>The trustee of this ACE entry</summary>
		public Win32Trustee Trustee { get; set; }

		/// <summary>Initializes a <see cref="Win32ACE"/></summary>
		public Win32ACE(ManagementObject managementObject=null, ConnectionInfo connectionInfo=null) { }
		/// <summary>Converts a Win32ACE object to a ManagementBaseObject object</summary>
		public static implicit operator ManagementBaseObject(Win32ACE obj)
		{
			var mgmtObj = new ManagementClass(Scope_, Class_, null);
			mgmtObj["AccessMask"] = obj.AccessMask;
			mgmtObj["AceFlags"] = obj.AceFlags;
			mgmtObj["AceType"] = obj.AceType;
			mgmtObj["GuidInheritedObjectType"] = obj.GuidInheritedObjectType;
			mgmtObj["GuidObjectType"] = obj.GuidObjectType;
			mgmtObj["TIME_CREATED"] = obj.TIMECREATED;
			mgmtObj["Trustee"] = obj.Trustee;
			return mgmtObj;
		}
		/// <summary>Converts a ManagementBaseObject to a Win32ACE object</summary>
		public static implicit operator Win32ACE(ManagementBaseObject mgmtObj)
		{
			var obj = new Win32ACE();
			obj.AccessMask = (UInt32)mgmtObj["AccessMask"];
			obj.AceFlags = (UInt32)mgmtObj["AceFlags"];
			obj.AceType = (Win32ACEAceType)mgmtObj["AceType"];
			obj.GuidInheritedObjectType = (string)mgmtObj["GuidInheritedObjectType"];
			obj.GuidObjectType = (string)mgmtObj["GuidObjectType"];
			obj.TIMECREATED = (UInt64)mgmtObj["TIME_CREATED"];
			obj.Trustee = (Win32Trustee)mgmtObj["Trustee"];
			return obj;
		}
		private const String Scope_ = @"root\CIMv2";
		private const String Class_ = @"Win32_ACE";
	}
	/// <summary>Win32ACE.AceType</summary>
	public enum Win32ACEAceType : uint
	{
		/// <summary>AccessAllowed</summary>
		AccessAllowed = 0,
		/// <summary>AccessDenied</summary>
		AccessDenied = 1,
		/// <summary>Audit</summary>
		Audit = 2
	}
	/// <summary>/// </summary>
	[WMIClass(Name = "Win32_SecurityDescriptor", Namespace = @"root\CIMv2")]
	public class Win32SecurityDescriptor
	{
		/// <summary>Bit flags that provide information about the descriptor's contents and format</summary>
		[Qualifier(Name="CIMTYPE", Data="uint32")]
		public UInt32 ControlFlags { get; set; }

		/// <summary>An array of Win32_ACE entries that specify access to the object</summary>
		public Win32ACE[] DACL { get; set; }

		/// <summary>The trustee representing the group of the object</summary>
		public Win32Trustee Group { get; set; }

		/// <summary>The trustee representing the owner of the object</summary>
		public Win32Trustee Owner { get; set; }

		/// <summary>An array of Win32_ACE entries that specify which users/groups auditing information is gathered for</summary>
		public Win32ACE[] SACL { get; set; }

		/// <summary>TIMECREATED</summary>
		[Qualifier(Name="CIMTYPE", Data="uint64")]
		public UInt64 TIMECREATED { get; set; }

		/// <summary>Initializes a <see cref="Win32SecurityDescriptor"/></summary>
		public Win32SecurityDescriptor(ManagementObject managementObject=null, ConnectionInfo connectionInfo=null) { }
		/// <summary>Converts a Win32SecurityDescriptor object to a ManagementBaseObject object</summary>
		public static implicit operator ManagementBaseObject(Win32SecurityDescriptor obj)
		{
			var mgmtObj = new ManagementClass(Scope_, Class_, null);
			mgmtObj["ControlFlags"] = obj.ControlFlags;
			mgmtObj["DACL"] = obj.DACL;
			mgmtObj["Group"] = obj.Group;
			mgmtObj["Owner"] = obj.Owner;
			mgmtObj["SACL"] = obj.SACL;
			mgmtObj["TIME_CREATED"] = obj.TIMECREATED;
			return mgmtObj;
		}
		/// <summary>Converts a ManagementBaseObject to a Win32SecurityDescriptor object</summary>
		public static implicit operator Win32SecurityDescriptor(ManagementBaseObject mgmtObj)
		{
			var obj = new Win32SecurityDescriptor();
			obj.ControlFlags = (UInt32)mgmtObj["ControlFlags"];
			obj.DACL = (Win32ACE[])mgmtObj["DACL"];
			obj.Group = (Win32Trustee)mgmtObj["Group"];
			obj.Owner = (Win32Trustee)mgmtObj["Owner"];
			obj.SACL = (Win32ACE[])mgmtObj["SACL"];
			obj.TIMECREATED = (UInt64)mgmtObj["TIME_CREATED"];
			return obj;
		}
		private const String Scope_ = @"root\CIMv2";
		private const String Class_ = @"Win32_SecurityDescriptor";
	}
	/// <summary>security settings for a logical file/// </summary>
	[WMIClass(Name = "Win32_LogicalShareSecuritySetting", Namespace = @"root\CIMv2")]
	public class Win32LogicalShareSecuritySetting
	{
		/// <summary>A short textual description (one-line string) of the CIM_Setting object.</summary>
		[Constraint(MaximumLength = 64)]
		public string Caption { get; set; }

		/// <summary>ControlFlags</summary>
		[Qualifier(Name="CIMTYPE", Data="uint32")]
		public UInt32 ControlFlags { get; set; }

		/// <summary>A textual description of the CIM_Setting object.</summary>
		public string Description { get; set; }

		/// <summary>The name of the share</summary>
		public string Name { get; set; }

		/// <summary>The identifier by which the CIM_Setting object is known.</summary>
		[Constraint(MaximumLength = 256)]
		public string SettingID { get; set; }

		/// <summary>Invokes Win32_LogicalShareSecuritySetting method GetSecurityDescriptor</summary>
		public Tuple<Win32SecurityDescriptor,UInt32> GetSecurityDescriptor()
		{
			ManagementBaseObject inParameters = null;
			var rv = _managementObject.InvokeMethod("GetSecurityDescriptor", inParameters, null);
			return Tuple.Create((Win32SecurityDescriptor)(ManagementBaseObject)(rv.Properties["Descriptor"].Value), (UInt32)(rv.Properties["ReturnValue"].Value));
		}
		/// <summary>Invokes Win32_LogicalShareSecuritySetting method SetSecurityDescriptor</summary>
		public UInt32 SetSecurityDescriptor(Win32SecurityDescriptor descriptor)
		{
			var rv = (UInt32)_managementObject.InvokeMethod("SetSecurityDescriptor", new object[] { (ManagementBaseObject)descriptor });
			return rv;
		}
		/// <summary>Initializes a <see cref="Win32LogicalShareSecuritySetting"/></summary>
		public Win32LogicalShareSecuritySetting(ManagementObject managementObject=null, ConnectionInfo connectionInfo=null) { _managementObject = managementObject; _connectionInfo = connectionInfo; }
		private readonly ManagementObject _managementObject;
		private readonly ConnectionInfo _connectionInfo;
		/// <summary>Converts a Win32LogicalShareSecuritySetting object to a ManagementBaseObject object</summary>
		public static implicit operator ManagementBaseObject(Win32LogicalShareSecuritySetting obj)
		{
			var mgmtObj = new ManagementClass(Scope_, Class_, null);
			mgmtObj["Caption"] = obj.Caption;
			mgmtObj["ControlFlags"] = obj.ControlFlags;
			mgmtObj["Description"] = obj.Description;
			mgmtObj["Name"] = obj.Name;
			mgmtObj["SettingID"] = obj.SettingID;
			return mgmtObj;
		}
		/// <summary>Converts a ManagementBaseObject to a Win32LogicalShareSecuritySetting object</summary>
		public static implicit operator Win32LogicalShareSecuritySetting(ManagementBaseObject mgmtObj)
		{
			var obj = new Win32LogicalShareSecuritySetting();
			obj.Caption = (string)mgmtObj["Caption"];
			obj.ControlFlags = (UInt32)mgmtObj["ControlFlags"];
			obj.Description = (string)mgmtObj["Description"];
			obj.Name = (string)mgmtObj["Name"];
			obj.SettingID = (string)mgmtObj["SettingID"];
			return obj;
		}
		private const String Scope_ = @"root\CIMv2";
		private const String Class_ = @"Win32_LogicalShareSecuritySetting";
	}
	/// <summary>The Win32_Share class represents a shared resource on a Win32 system. This may be a disk drive, printer, interprocess communication, or other shareable device.  Example: C:\PUBLIC./// </summary>
	[WMIClass(Name = "Win32_Share", Namespace = @"root\CIMv2")]
	public class Win32Share
	{
		/// <summary>This property has been deprecated in favour of the GetAccessMask method of this class due to the expense of calling GetEffectiveRightsFromAcl. The value will be set to NULL</summary>
		[Qualifier(Name="CIMTYPE", Data="uint32")]
		public UInt32 AccessMask { get; set; }

		/// <summary>The AllowMaximum property indicates whether the number of concurrent users for this resource has been limited.Values: TRUE or FALSE. A value of TRUE indicates the number of concurrent users of this resource has not been limited and the value in the MaximumAllowed property is ignored.</summary>
		[Qualifier(Name="CIMTYPE", Data="boolean")]
		public bool AllowMaximum { get; set; }

		/// <summary>The Caption property is a short textual description (one-line string) of the object.</summary>
		[Constraint(MaximumLength = 64)]
		public string Caption { get; set; }

		/// <summary>The Description property provides a textual description of the object. </summary>
		public string Description { get; set; }

		/// <summary>The InstallDate property is datetime value indicating when the object was installed. A lack of a value does not indicate that the object is not installed.</summary>
		[Qualifier(Name="CIMTYPE", Data="datetime")]
		public DateTime InstallDate { get; set; }

		/// <summary>The MaximumAllowed property indicates the limit on the maximum number of users allowed to use this resource concurrently. The value is only valid if the AllowMaximum member set to FALSE Example: 10.</summary>
		[Qualifier(Name="CIMTYPE", Data="uint32")]
		public UInt32 MaximumAllowed { get; set; }

		/// <summary>The Name property indicates the alias given to a path set up as a share on a  Win32 system.Example: public.</summary>
		public string Name { get; set; }

		/// <summary>The Path property indicates the local path of the Win32 share.Example: C:\Program Files</summary>
		public string Path { get; set; }

		// values OK, Error, Degraded, Unknown, Pred Fail, Starting, Stopping, Service, Stressed, NonRecover, No Contact, Lost Comm
		/// <summary>The Status property is a string indicating the current status of the object. Various operational and non-operational statuses can be defined. Operational statuses are "OK", "Degraded" and "Pred Fail". "Pred Fail" indicates that an element may be functioning properly but predicting a failure in the near future. An example is a SMART-enabled hard drive. Non-operational statuses can also be specified. These are "Error", "Starting", "Stopping" and "Service". The latter, "Service", could apply during mirror-resilvering of a disk, reload of a user permissions list, or other administrative work. Not all such work is on-line, yet the managed element is neither "OK" nor in one of the other states.</summary>
		[Constraint(MaximumLength = 10)]
		public Win32ShareStatus Status { get; set; }

		// values Disk Drive, Print Queue, Device, IPC, Disk Drive Admin, Print Queue Admin, Device Admin, IPC Admin
		/// <summary>The Type property specifies the type of resource being shared. Types include disk drives, print queues, interprocess communications (IPC), and general devices.</summary>
		[Qualifier(Name="CIMTYPE", Data="uint32")]
		public Win32ShareType Type { get; set; }

		/// <summary>Invokes Win32_Share method Create on the local machine</summary>
		public static UInt32 Create(string path, string name, UInt32 type, UInt32 maximumAllowed = default(UInt32), string description = default(string), string password = default(string), Win32SecurityDescriptor access = default(Win32SecurityDescriptor))
		{
			var rv = (UInt32)ManagementClass.InvokeMethod("Create", new object[] { path, name, type, maximumAllowed, description, password, (ManagementBaseObject)access });
			return rv;
		}
		/// <summary>Invokes Win32_Share method Create using the given connection information</summary>
		public static UInt32 Create(ConnectionInfo connectionInfo, string path, string name, UInt32 type, UInt32 maximumAllowed = default(UInt32), string description = default(string), string password = default(string), Win32SecurityDescriptor access = default(Win32SecurityDescriptor))
		{
			var mgmtClass = new ManagementClass((connectionInfo.Options == null ? new ManagementScope(Scope_) : new ManagementScope(Scope_, connectionInfo.Options)), new ManagementPath(Class_), null);
			return (UInt32)mgmtClass.InvokeMethod("Create", new object[] { path, name, type, maximumAllowed, description, password, (ManagementBaseObject)access });
		}
		/// <summary>Invokes Win32_Share method SetShareInfo</summary>
		public UInt32 SetShareInfo(UInt32 maximumAllowed = default(UInt32), string description = default(string), Win32SecurityDescriptor access = default(Win32SecurityDescriptor))
		{
			var rv = (UInt32)_managementObject.InvokeMethod("SetShareInfo", new object[] { maximumAllowed, description, (ManagementBaseObject)access });
			return rv;
		}
		/// <summary>Invokes Win32_Share method GetAccessMask</summary>
		public UInt32 GetAccessMask()
		{
			var rv = (UInt32)_managementObject.InvokeMethod("GetAccessMask", new object[0]);
			return rv;
		}
		/// <summary>Invokes Win32_Share method Delete</summary>
		public UInt32 Delete()
		{
			var rv = (UInt32)_managementObject.InvokeMethod("Delete", new object[0]);
			return rv;
		}
		/// <summary>Initializes a <see cref="Win32Share"/></summary>
		public Win32Share(ManagementObject managementObject=null, ConnectionInfo connectionInfo=null) { _managementObject = managementObject; _connectionInfo = connectionInfo; }
		private readonly ManagementObject _managementObject;
		private readonly ConnectionInfo _connectionInfo;
		/// <summary>Converts a Win32Share object to a ManagementBaseObject object</summary>
		public static implicit operator ManagementBaseObject(Win32Share obj)
		{
			var mgmtObj = new ManagementClass(Scope_, Class_, null);
			mgmtObj["AccessMask"] = obj.AccessMask;
			mgmtObj["AllowMaximum"] = obj.AllowMaximum;
			mgmtObj["Caption"] = obj.Caption;
			mgmtObj["Description"] = obj.Description;
			mgmtObj["InstallDate"] = obj.InstallDate;
			mgmtObj["MaximumAllowed"] = obj.MaximumAllowed;
			mgmtObj["Name"] = obj.Name;
			mgmtObj["Path"] = obj.Path;
			mgmtObj["Status"] = obj.Status.ToString();
			mgmtObj["Type"] = obj.Type;
			return mgmtObj;
		}
		/// <summary>Converts a ManagementBaseObject to a Win32Share object</summary>
		public static implicit operator Win32Share(ManagementBaseObject mgmtObj)
		{
			var obj = new Win32Share();
			obj.AccessMask = (UInt32)mgmtObj["AccessMask"];
			obj.AllowMaximum = (bool)mgmtObj["AllowMaximum"];
			obj.Caption = (string)mgmtObj["Caption"];
			obj.Description = (string)mgmtObj["Description"];
			obj.InstallDate = (DateTime)mgmtObj["InstallDate"];
			obj.MaximumAllowed = (UInt32)mgmtObj["MaximumAllowed"];
			obj.Name = (string)mgmtObj["Name"];
			obj.Path = (string)mgmtObj["Path"];
			obj.Status = (Win32ShareStatus)mgmtObj["Status"];
			obj.Type = (Win32ShareType)mgmtObj["Type"];
			return obj;
		}

		private static readonly object ManagementClassSync = new object();
		private static ManagementClass _managementClass;
		private static ManagementClass ManagementClass { get { lock(ManagementClassSync) { return (_managementClass ?? (_managementClass = new ManagementClass(Scope_, Class_, null))); }}}
		private const String Scope_ = @"root\CIMv2";
		private const String Class_ = @"Win32_Share";
	}
	/// <summary>Win32Share.Status</summary>
	public enum Win32ShareStatus : uint
	{
		/// <summary>OK</summary>
		OK,
		/// <summary>Error</summary>
		Error,
		/// <summary>Degraded</summary>
		Degraded,
		/// <summary>Unknown</summary>
		Unknown,
		/// <summary>PredFail</summary>
		PredFail,
		/// <summary>Starting</summary>
		Starting,
		/// <summary>Stopping</summary>
		Stopping,
		/// <summary>Service</summary>
		Service,
		/// <summary>Stressed</summary>
		Stressed,
		/// <summary>Nonrecover</summary>
		Nonrecover,
		/// <summary>NoContact</summary>
		NoContact,
		/// <summary>LostComm</summary>
		LostComm
	}
	/// <summary>Win32Share.Type</summary>
	public enum Win32ShareType : uint
	{
		/// <summary>DiskDrive</summary>
		DiskDrive = 0,
		/// <summary>PrintQueue</summary>
		PrintQueue = 1,
		/// <summary>Device</summary>
		Device = 2,
		/// <summary>IPC</summary>
		IPC = 3,
		/// <summary>DiskDriveAdmin</summary>
		DiskDriveAdmin = 2147483648,
		/// <summary>PrintQueueAdmin</summary>
		PrintQueueAdmin = 2147483649,
		/// <summary>DeviceAdmin</summary>
		DeviceAdmin = 2147483650,
		/// <summary>IPCAdmin</summary>
		IPCAdmin = 2147483651
	}
}
